<template>
  <div>
    <!--  表单部分，当前部分为销售调价-->
    <el-form :model="inputForm" ref="inputForm" v-loading="loading" :disabled="formReadOnly"
             label-width="120px">
      <el-row :gutter="15">
        <el-col :span="24">
          <el-form-item label="业务编号:" prop="codes">
            <el-input v-model="inputForm.codes" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="companyType+':'" prop="companyName">
            <el-input v-model="inputForm.companyName" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item :label="productType+':'" prop="productId">
            <el-input v-model="inputForm.productName" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="调整价格:" prop="displayPrice">
            <el-input :disabled="true" v-model="inputForm.displayPrice"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="支付方式:" prop="payMode">
            <el-select clearable v-model="inputForm.payMode" :disabled="true" placeholder="请选择支付方式">
              <el-option
                v-for="item in  $dictUtils.getDictList('payMode')"
                :key="item.value"
                :label="item.label"
                :value="Number(item.value)">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="执行时间:" prop="effectTime">
            <el-date-picker
              v-model="inputForm.effectTime"
              type="datetime"
              :disabled="true"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期时间"
            >
            </el-date-picker>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>

<script>
  import UserSelect from '@/components/userSelect'
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  export default {
    data() {
      return {
        title: '',
        method: '',
        loading: false,
        companyType: '客户名称',
        productType: '产品名称',
        inputForm: {
          id: '',
          businessProductId: '',
          procInsId: '',
          businessId: '',
          productId: '',
          payMode: 0,
          selectVos: [],
          companyName: '',
          price: '',
          productName: '',
          contractCode: '',
          effectTime: '',
          newPrice: ''
        }
      }
    },
    props: {
      businessId: {
        type: String,
        default: ''
      },
      formReadOnly: {
        type: Boolean,
        default: false
      },
        businessType: {
          type: Number
        }
    },
    components: {
      UserSelect,
      SelectTree
    },
    watch: {
      // 例如：当前为调价审批表单，对应的是销售调价业务，表是：t_business_product
      // 这里的business就指的是t_business_product的一个主键ID
      'businessId': {
        handler(newVal) {
          if (this.businessId) {
            this.init(this.businessId)
          } else {
            this.$nextTick(() => {
              this.$refs.inputForm.resetFields()
            })
          }
        },
        immediate: true,
        deep: false
      }
    },
    methods: {
      // 根据主键ID从接口获取详情数据
      init(id) {
        if (id) {
          this.loading = true
          this.inputForm.id = id
          this.$nextTick(() => {
            this.$refs.inputForm.resetFields()
            this.$http({
              url: `/businessProduct/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.result)
              this.loading = false
            })
          })
        }
      }
    },
      mounted () {
          if (this.businessType === 2) {
              this.companyType = '供应商名称'
              this.productType = '原料名称'
          }
      }
  }
</script>
